angular.module('BaseControl')

.directive("dropdownbutton", [function() {
    return {
        restrict: "E",	// 指令是一个元素 (并非属性)，备选项有"A"、"E" 和 "C"， "M" ,分别代表attribute、element、class和comment（默认值为"A"）
        scope: {
            value: '@'
        },
        template: 		// 替换HTML (使用scope中的变量)
        '<div class="btn-group" ng-show="Visible">' +
            '<button type="button" ng-disabled="!Enabled" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{value}} <span class="caret"></span></button>' +
                '<ul class="dropdown-menu" style="min-width:100px;box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);" ng-transclude>' +
                '因为定义了ng-transclude属性，所以该段文字是不会被看见的</ul>' +
        '</div>',
        replace: true,			// 使用模板替换原始标记
        transclude: true,		// 不复制原始HTML内容
        controller:function(){
        },
        link: function (scope, element, attrs) {
            scope.Enabled = true;
            scope.Visible = true;

            scope.$watch(
                function(){
                    return attrs["enabled"];
                },
                function(){
                    if (attrs["enabled"] != undefined && attrs["enabled"].trim().toLocaleLowerCase() == "false") {
                        scope.Enabled = false;
                    }
                    else{
                        scope.Enabled = true;
                    }
                }
            );

            scope.$watch(
                function(){
                    return attrs["visible"]
                },
                function(){
                    if (attrs["visible"] != undefined && attrs["visible"].trim().toLocaleLowerCase() == "false") {
                        scope.Visible = false;
                    }
                    else{
                        scope.Visible = true;
                    }
                }
            );
        }
    }
}])

.directive("buttonoption", [function() {
    return {
        restrict: "E",	// 指令是一个元素 (并非属性)，备选项有"A"、"E" 和 "C"， "M" ,分别代表attribute、element、class和comment（默认值为"A"）
        scope: {
            value: '@'
        },
        template: 		// 替换HTML (使用scope中的变量)
        '<li ng-show="Visible"><a style="cursor:pointer;">{{value}}</a></li>',
        replace: true,			// 使用模板替换原始标记
        transclude: true,
        link: function (scope, element, attrs) {
            scope.Visible = true;

            scope.$watch(
                function(){
                    return attrs["visible"]
                },
                function(){
                    if (attrs["visible"] != undefined && attrs["visible"].trim().toLocaleLowerCase() == "false") {
                        scope.Visible = false;
                    }
                    else{
                        scope.Visible = true;
                    }
                }
            );
        }
    }
}]);
